#include<bits/stdc++.h>
using namespace std;
const int N=5e4+5;
int n,m,f,fa[N],a[N],qwq[N],l,r,sum,bj[N],ans;
vector<int>q[N];
int dfs(int i)
{
	int o=0,pd=0;
	if(l<=qwq[i]&&qwq[i]<=r)
		o=1,++ans;
	for(int j=0;j<q[i].size();++j)
	{
		if(fa[i]==q[i][j]) continue;
		fa[q[i][j]]=i;
		if(dfs(q[i][j]))
			++pd;
	}
	if(pd>1&&!o)
		++ans;
	return o+pd;
}
int main()
{
	freopen("escape.in","r",stdin);
	freopen("escape.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<n;++i)
	{
		cin>>f;
		q[f].push_back(i+1);
	}
	for(int i=1;i<=n;++i)
		cin>>a[i],qwq[a[i]]=i;
	for(int i=1;i<=m;++i)
	{
		ans=0;
		cin>>l>>r;
		if(n<=20000)
		{
			dfs(1);
			cout<<ans<<'\n';
		}
		else
			cout<<r-l+1<<'\n';
	}
	return 0;
 } 
